package gui;
import gui.menu.PanelMenuView;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;

import terminal.TerminalHandler;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings({  "serial" })
public class GUIMainFrame extends javax.swing.JFrame {
	private JPanel statusPanel;
	private JScrollPane consoleScrollPane1;
	private JButton menuButton;
	private JTextField consoleTextField;
	private HandViewPanel handPanel;
	private CardViewPanel infoPanel = CardViewPanel.getInstance();
	private JTextArea consoleTextArea;
	private JPanel bottomPanel;
	private CenterPanel centerPanel;
	private final String newline = "\n";
	private PanelMenuView menuPanel;


	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	/**
	* Auto-generated main method to display this JFrame
	*/

	public GUIMainFrame() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setTitle("Conquerors!");
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setPreferredSize(new java.awt.Dimension(1000, 834));
			{
				statusPanel = StatusPanel.getInstance();
				getContentPane().add(statusPanel, BorderLayout.NORTH);
				statusPanel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				{
					menuButton = new JButton();
					statusPanel.add(menuButton, BorderLayout.EAST);
					menuButton.setLayout(null);
					menuButton.setText("Menu");
					menuButton.setPreferredSize(new java.awt.Dimension(65, 26));
					menuButton.addActionListener(new java.awt.event.ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							if(menuPanel.isVisible())
							menuPanel.setVisible(false);
							else
								menuPanel.setVisible(true);
						}

					});
				}
				bottomPanel = new JPanel();
				GroupLayout bottomPanelLayout = new GroupLayout((JComponent)bottomPanel);
				getContentPane().add(bottomPanel, BorderLayout.SOUTH);
				bottomPanel.setLayout(bottomPanelLayout);
				bottomPanel.setPreferredSize(new java.awt.Dimension(1000, 200));
				bottomPanel.setBackground(Color.black);
				{
					consoleScrollPane1 = new JScrollPane();
					{
						consoleTextArea = new JTextArea("",555,20);
						consoleTextArea.setBackground(Color.black);
						consoleTextArea.setForeground(Color.white);
						consoleScrollPane1.setViewportView(consoleTextArea);
						consoleTextArea.setSize(330, 154);
						consoleTextArea.setPreferredSize(new java.awt.Dimension(308, 115));
						consoleTextArea.setEditable(false);
					}
				}
				
				
					handPanel = HandViewPanel.getInstance();
				
				{
					consoleTextField = new JTextField();
					consoleTextField.setBackground(Color.black);
					consoleTextField.setForeground(Color.white);
					consoleTextField.setText("");
					consoleTextField.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent evt) {
							// TODO priority 2 to be changed when GUI- core and controller is in place	
				            TerminalHandler.getTerminal().Execute(evt.getActionCommand());
				            String text = consoleTextField.getText();
				            consoleTextField.setText("");
				            consoleTextArea.append(text + newline);
				            consoleTextArea.append(TerminalHandler.getTerminal().getOutputText() + newline);
				            centerPanel.repaint();
				        }
				    });
				}
					bottomPanelLayout.setHorizontalGroup(bottomPanelLayout.createSequentialGroup()
					.addGap(7)
					.addGroup(bottomPanelLayout.createParallelGroup()
					    .addComponent(consoleScrollPane1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 301, GroupLayout.PREFERRED_SIZE)
					    .addComponent(consoleTextField, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 301, GroupLayout.PREFERRED_SIZE))
					//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(infoPanel, GroupLayout.PREFERRED_SIZE, 375, GroupLayout.PREFERRED_SIZE)
					//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(handPanel, GroupLayout.PREFERRED_SIZE, 317, GroupLayout.PREFERRED_SIZE)
					.addGap(0, 7, Short.MAX_VALUE));
					bottomPanelLayout.setVerticalGroup(bottomPanelLayout.createParallelGroup()
					.addGroup(GroupLayout.Alignment.LEADING, bottomPanelLayout.createSequentialGroup()
					    .addComponent(consoleScrollPane1, 0, 118, Short.MAX_VALUE)
					    .addComponent(consoleTextField, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))
					.addComponent(handPanel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
					.addComponent(infoPanel, GroupLayout.Alignment.LEADING, 0, 200, Short.MAX_VALUE));
			}
			{
				menuPanel = PanelMenuView.getInstance();
				getContentPane().add(menuPanel, BorderLayout.EAST);
				menuPanel.setPreferredSize(new java.awt.Dimension(200,200));
				menuPanel.setVisible(false);
				menuPanel.setSize(200, 200);
			}
			{
				centerPanel = CenterPanel.getInstance();
				CenterPanelReader.registerCenterPanel(centerPanel);
				getContentPane().add(centerPanel, BorderLayout.CENTER );
				BorderLayout centerPanelLayout = new BorderLayout();
				centerPanel.setPreferredSize(new java.awt.Dimension(992, 651));
				centerPanel.setLayout(centerPanelLayout);
				centerPanel.setSize(1000, 200);
			}
			pack();
			setDefaultCloseOperation(EXIT_ON_CLOSE);
			this.setSize(1016, 820);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
